

 import router from "./router"
 import store from "./store"
 
 //定义一个白名单
 const whiteList = ["/login","/404","/401"]
 
 router.beforeEach(async (to,from,next)=>{
     if(store.getters.token){
         //登录
         if(to.path == "/login"){
             next("/")
         }else{
             if(store.token){
                 next()
             }else{
                 let res = await store.dispatch("getUserInfo");
                 console.log(res);
                //  let menus = res.permission.menus;
                //  const routes = await store.dispatch("filterRoutes", menus)
                //  routes.forEach(item => {
                //      router.addRoute(item)
                //  })
                // console.log(routes);
                
                 return next()
             }
             
         }
     }else{
         //未登录
         if(whiteList.indexOf(to.path) > -1){
             next()
         }else{
             next("/login")
         }
     }
 })